<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%files_classify}}`.
 */
class m230730_090415_create_files_classify_table extends Migration
{
    const TABLE_NAME = '{{%files_classify}}';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ENGINE=MyISAM COMMENT="文件分类表"';
        }

        $this->createTable(self::TABLE_NAME, [
            'id' => $this->primaryKey(),
            'pid' => $this->integer()->notNull()->defaultValue(0)->comment('父ID'),
            'name' => $this->string(10)->notNull()->defaultValue('')->comment('名称'),
            'path' => $this->string()->notNull()->defaultValue('')->comment('路径, 如:-0-1-'),
            'created_at' => $this->dateTime()->notNull(),
            'updated_at' => $this->dateTime()->defaultValue(null),
        ], $tableOptions);

        $this->createIndex('idx_pid', self::TABLE_NAME, ['pid']);

        $this->batchInsert(self::TABLE_NAME, ['id', 'pid', 'name', 'path', 'created_at', 'updated_at'], [
            [1, 0, '图片', '-0-', date('Y-m-d H:i:s'), date('Y-m-d H:i:s')],
            [2, 0, '视频', '-0-', date('Y-m-d H:i:s'), date('Y-m-d H:i:s')],
            [3, 0, '音频', '-0-', date('Y-m-d H:i:s'), date('Y-m-d H:i:s')],
            [4, 0, '其他', '-0-', date('Y-m-d H:i:s'), date('Y-m-d H:i:s')],
            [5, 0, '客户上传', '-0-', date('Y-m-d H:i:s'), date('Y-m-d H:i:s')],
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable(self::TABLE_NAME);
    }
}
